home *** CD-ROM | disk | FTP | other *** search
/ Teach Your Children: Road Construction Ahead / Teach Your Children: Road Construction Ahead.iso / pc / rca / road.dxr / 00021_Culvert Class.ls < prev    next >
Encoding:
Text File  |  1996-07-17  |  6.8 KB  |  289 lines

  1. property state, hooked, hookChan, culvertChan, centerVertList, rightVertList, horizList, demoMove, firstArrowChan, buttonData, sandboxChan, demoMoveList, animCounter, task, demoCounter, arrowChannel
  2. global gSimObject, gTruckObject, gLevelObject
  3.  
  4. on birth me
  5.   set state to 1
  6.   set task to EMPTY
  7.   set hooked to 0
  8.   set culvertChan to 4
  9.   set hookChan to 5
  10.   set firstArrowChan to 7
  11.   set sandboxChan to 27
  12.   set centerVertList to [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1]
  13.   set rightVertList to [1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1]
  14.   set horizList to [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1]
  15.   set buttonData to [1: [0, 1, 1, 1], 2: [0, 1, 0, 0], 3: [1, 0, 0, 0], 4: [0, 0, 1, 1], 5: [1, 0, 0, 0]]
  16.   set demoMoveList to ["right", "down", "up", "left", "down"]
  17.   return me
  18. end
  19.  
  20. on setup me
  21.   puppetPalette(0)
  22.   if the demoFlag of gSimObject <> 1 then
  23.     add(gActorList, birth(script "Rollover Anim Button Class", "goMenu( gCulvertObject, me )", 27, 27, 5, "RCA-07VO01", "RCA-07RO01"))
  24.     add(gActorList, birth(script "Rollover Anim Button Class", "help( gCulvertObject, me )", 28, 28, 11, EMPTY, "RCA-05RO02"))
  25.   else
  26.     set demoCounter to 0
  27.     set task to "demo( me )"
  28.   end if
  29.   set state to 1
  30.   set task to EMPTY
  31.   set hooked to 0
  32.   set the visible of sprite firstArrowChan to 0
  33.   puppetSprite(hookChan, 1)
  34.   puppetSprite(culvertChan, 1)
  35.   add(gActorList, me)
  36. end
  37.  
  38. on update me
  39.   if task = EMPTY then
  40.     if the demoFlag of gSimObject then
  41.       Demo(me)
  42.     end if
  43.   else
  44.     do(task)
  45.   end if
  46. end
  47.  
  48. on Demo me
  49.   set demoCounter to demoCounter + 1
  50.   set demoMove to getAt(demoMoveList, demoCounter)
  51.   set arrowChannel to firstArrowChan + getPos(["up", "right", "down", "left"], demoMove) - 1
  52.   set the castNum of sprite arrowChannel to the castNum of sprite arrowChannel + 1
  53.   puppetSprite(arrowChannel, 1)
  54.   set animCounter to 0
  55.   puppetSound("arrowClick")
  56.   updateStage()
  57.   set task to "executeButton( me )"
  58. end
  59.  
  60. on executeButton me
  61.   if not soundBusy(1) then
  62.     clearTask(me)
  63.     set the castNum of sprite arrowChannel to the castNum of sprite arrowChannel - 1
  64.     puppetSprite(arrowChannel, 0)
  65.     set animCounter to 0
  66.     puppetSound("1020machine")
  67.     do(demoMove & "Button( me )")
  68.   end if
  69. end
  70.  
  71. on arrowButton me, direction
  72.   set animCounter to 0
  73.   buttonSound(me)
  74.   hideOtherActors(me)
  75.   do(direction & "Button( me )")
  76. end
  77.  
  78. on upButton me
  79.   if state = 3 then
  80.     set task to "upCenter( me )"
  81.   else
  82.     if state = 5 then
  83.       set task to "upRight( me )"
  84.     end if
  85.   end if
  86. end
  87.  
  88. on upCenter me
  89.   set animCounter to animCounter + 1
  90.   if animCounter <= count(centerVertList) then
  91.     moveVert(me, -1 * getAt(centerVertList, animCounter))
  92.   else
  93.     clearTask(me)
  94.     set state to 1
  95.     updateButtons(me)
  96.   end if
  97. end
  98.  
  99. on upRight me
  100.   set animCounter to animCounter + 1
  101.   if animCounter <= count(rightVertList) then
  102.     moveVert(me, -1 * getAt(rightVertList, animCounter))
  103.   else
  104.     clearTask(me)
  105.     set state to 4
  106.     updateButtons(me)
  107.   end if
  108. end
  109.  
  110. on downButton me
  111.   if state = 1 then
  112.     set task to "downCenter( me )"
  113.   else
  114.     if state = 4 then
  115.       set task to "downRight( me )"
  116.     end if
  117.   end if
  118. end
  119.  
  120. on downCenter me
  121.   set animCounter to animCounter + 1
  122.   if animCounter <= count(centerVertList) then
  123.     moveVert(me, getAt(centerVertList, animCounter))
  124.   else
  125.     clearTask(me)
  126.     if hooked then
  127.       bridgeDone(me)
  128.     else
  129.       set state to 3
  130.       updateButtons(me)
  131.     end if
  132.   end if
  133. end
  134.  
  135. on downRight me
  136.   set animCounter to animCounter + 1
  137.   if animCounter <= count(rightVertList) then
  138.     moveVert(me, getAt(rightVertList, animCounter))
  139.   else
  140.     clearTask(me)
  141.     set hooked to 1
  142.     set state to 5
  143.     updateButtons(me)
  144.   end if
  145. end
  146.  
  147. on rightButton me
  148.   set task to "goRight( me )"
  149. end
  150.  
  151. on goRight me
  152.   set animCounter to animCounter + 1
  153.   if animCounter <= count(horizList) then
  154.     moveHoriz(me, getAt(horizList, animCounter))
  155.   else
  156.     clearTask(me)
  157.     if state = 2 then
  158.       set state to 1
  159.     else
  160.       if state = 1 then
  161.         set state to 4
  162.       end if
  163.     end if
  164.     updateButtons(me)
  165.   end if
  166. end
  167.  
  168. on leftButton me
  169.   set task to "goLeft( me )"
  170. end
  171.  
  172. on goLeft me
  173.   set animCounter to animCounter + 1
  174.   if animCounter <= count(horizList) then
  175.     moveHoriz(me, -1 * getAt(horizList, animCounter))
  176.   else
  177.     clearTask(me)
  178.     if state = 1 then
  179.       set state to 2
  180.     else
  181.       if state = 4 then
  182.         set state to 1
  183.       end if
  184.     end if
  185.     updateButtons(me)
  186.   end if
  187. end
  188.  
  189. on moveVert me, delta
  190.   set the locV of sprite hookChan to the locV of sprite hookChan + delta
  191.   if hooked then
  192.     set the locV of sprite culvertChan to the locV of sprite culvertChan + delta
  193.   end if
  194.   puppetTempo(40)
  195. end
  196.  
  197. on moveHoriz me, delta
  198.   set the locH of sprite hookChan to the locH of sprite hookChan + delta
  199.   if hooked then
  200.     set the locH of sprite culvertChan to the locH of sprite culvertChan + delta
  201.   end if
  202.   puppetTempo(40)
  203. end
  204.  
  205. on clearTask me
  206.   set animCounter to 0
  207.   set task to EMPTY
  208.   puppetSound(0)
  209.   showAllActors()
  210. end
  211.  
  212. on buttonSound me
  213.   puppetSound("arrowClick")
  214.   updateStage()
  215.   finishSound(me)
  216.   puppetSound("1020machine")
  217. end
  218.  
  219. on finishSound me
  220.   repeat while soundBusy(1)
  221.   end repeat
  222.   puppetSound(0)
  223. end
  224.  
  225. on updateButtons me
  226.   set buttonList to getProp(buttonData, state)
  227.   repeat with button = 1 to count(buttonList)
  228.     set boolean to getAt(buttonList, button)
  229.     set the visible of sprite (firstArrowChan + button - 1) to boolean
  230.   end repeat
  231.   finishSound(me)
  232. end
  233.  
  234. on bridgeDone me
  235.   set state to 1
  236.   set hooked to 0
  237.   clearAllActors()
  238.   finishSound(me)
  239.   go("BridgeDone")
  240.   puppetSprite(hookChan, 0)
  241.   puppetSprite(culvertChan, 0)
  242. end
  243.  
  244. on finished me
  245.   repeat with button = 1 to 4
  246.     set the visible of sprite (firstArrowChan + button - 1) to 1
  247.   end repeat
  248.   set x to blockCrossings(the cell of gTruckObject, getLast(the recordedMoveList of gSimObject))
  249.   makeBridge(gTruckObject)
  250.   keepSandboxBut(sandboxChan)
  251.   puppetPalette("RiverPal")
  252.   go("Grass")
  253.   go(the frame + 1)
  254.   puppetSprite(48, 0)
  255.   puppetPalette("SimPal", 60)
  256.   updateStage()
  257.   puppetPalette(0)
  258.   predrawSimButtons(gSimObject)
  259.   go(label("Simulator" & string(the level of gLevelObject)))
  260. end
  261.  
  262. on goMenu me, buttonObject
  263.   forgetObstacle(gSimObject)
  264.   set state to 1
  265.   set hooked to 0
  266.   clearAllActors()
  267.   unpuppetAll()
  268.   makeButtonJump(buttonObject)
  269.   puppetSprite(48, 0)
  270.   puppetPalette("RiverPal")
  271.   go("Grass")
  272.   go(the frame + 1)
  273.   repeat with button = 1 to 4
  274.     set the visible of sprite (firstArrowChan + button - 1) to 1
  275.   end repeat
  276.   unLoadCast()
  277.   goLocationMap()
  278. end
  279.  
  280. on help me, buttonObject
  281.   birth(script "Help Parent", buttonObject, #Culvert)
  282. end
  283.  
  284. on shortDelay me
  285.   startTimer()
  286.   repeat while the timer < 45
  287.   end repeat
  288. end
  289.